package com.yingsheng.bi.hks.template;

import com.yingsheng.bi.hks.template.events.Event;
import com.yingsheng.bi.hks.template.processor.Processor;

public class SimpleTemplate implements ITemplate {

    private ITemplate parent;

    private Processor entryLogic;

    private Processor exitLogic;

    public Processor getEntryLogic() {
        return entryLogic;
    }

    public void setEntryLogic(Processor entryLogic) {
        this.entryLogic = entryLogic;
    }

    public Processor getExitLogic() {
        return exitLogic;
    }

    public void setExitLogic(Processor exitLogic) {
        this.exitLogic = exitLogic;
    }

    public ITemplate getParent() {
        return parent;
    }

    @Override
    public void setParent(ITemplate parent) {
        this.parent = parent;
    }

    @Override
    public void entry(Event event) {
        if (entryLogic != null) {
            entryLogic.exec(event);
        }
        if (parent != null) {
            parent.entry(event);
        }
    }

    @Override
    public void exit(Event event) {
        if (parent != null) {
            parent.exit(event);
        }
        if (exitLogic != null) {
            exitLogic.exec(event);
        }
    }
}
